package com.yunfangdata.service.impl;

import com.yunfangdata.domain.FamilyBackground;
import com.yunfangdata.mapper.FamilyBackgroundMapper;
import com.yunfangdata.query.QueryObject;
import com.yunfangdata.service.IFamilyBackgroundService;
import com.yunfangdata.util.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class FamilyBackgroundServiceImpl implements IFamilyBackgroundService {

    @Autowired
    private FamilyBackgroundMapper mapper;

    public void save(FamilyBackground entity) {
        mapper.insert(entity);
    }

    public void delete(Long id) {
        mapper.deleteByPrimaryKey(id);
    }

    public void update(FamilyBackground entity) {
        mapper.updateByPrimaryKey(entity);
    }

    public FamilyBackground get(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    public List<FamilyBackground> list() {
        return mapper.selectAll();
    }

    public PageResult query(QueryObject qo) {
        int total = mapper.queryForCount(qo);
        if (total == 0){
            return new PageResult();
        }
        List<FamilyBackground> rows = mapper.queryForList(qo);
        return new PageResult(total,rows);
    }
}
